﻿@using CleanArchitecture.Core.Helper
@using CleanArchitecture.Infrastructure.Entities.SystemModules
@using CleanArchitecture.Infrastructure.Models.AdminUsers
@model AdminUserSearchModel
@{
    Layout = "_BackendLayout";
    ViewData["Title"] = ViewBag.PageTitle as string;
    int currentSystemModuleId = ViewBag.CurrentSystemModuleId;
    var adminuserModel = Model.CustomProperties["adminuserModel"] as AdminUserModel ?? null;
}
@section cssstyles {
    <style type="text/css">
        body {
            margin: 20px !important;
            display: flex;
            flex: auto;
            flex-direction: column;
            min-height: 0;
            background: #f0f2f5;
        }

        .adminusermanage {
            width: 100% !important;
            height: 100%;
            background-color: #fff;
            margin: 0 !important;
            padding: 10px 2px;
        }
    </style>
}
<div class="adminusermanage layui-main">
    <fieldset class="layui-elem-field">
        <div class="layui-field-box pagebuttongroup">
            <a class="layui-btn form-search-expand expand" data-formclassname="search-from" data-type="expand">
                展开搜索 <i class="layui-icon layui-icon-down"></i>
            </a>
            @await Component.InvokeAsync("PageButton")
        </div>
        <form class="layui-form search-from">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" style="width: 130px;">登录名/手机号:</label>
                    <div class="layui-input-inline">
                        <input name="@Model.nameof(m => m.SearchAccount)" class="layui-input" autocomplete="off" placeholder="请输入搜索账号信息" />
                    </div>
                    <div class="layui-form-mid layui-word-aux">不支持检索，请完整输入要查询账号的登录名/手机号</div>
                </div>
                <div class="layui-inline">
                    <button type="button" class="layui-btn icon-btn" lay-filter="tbAdvSearch" lay-submit="">
                        <i class="layui-icon layui-icon-search"></i>搜索
                    </button>
                </div>
            </div>
        </form>
    </fieldset>

    <table id="adminusermanagetable" lay-filter="adminusermanagetable"></table>
</div>
<input type="text" class="layui-hide" id="currentSystemModuleId" value="@currentSystemModuleId" />
@await Component.InvokeAsync("RecordButton")
<script type="text/html" id="isActiveTpl">
    <input type="checkbox" value="{{d.IsActive}}" lay-skin="switch" lay-text="正常|锁定" {{ d.IsActive ? 'checked' : '' }}>
</script>
@*<script type="text/html" id="roleNameTpl">
        {{#  layui.each(d.AvailableAdminRoles, function(index, item){ }}
        {{#  if(item.Selected) { }}
        <span class="layui-badge-rim">{{item.Text}}</span>
        {{#  } }}
        {{#  }); }}
        {{#  if(d.length === 0){ }}
        无数据
        {{#  } }}
    </script>*@
@section scripts{
    <script type="text/javascript">
    var adminusertableconfig = {
        elem: "#adminusermanagetable",
        url: '/api/backend/account/getadminusers',
        request: {
            pageName: '@Model.nameof(p => p.Page)', //页码的参数名称，默认：page
            limitName: '@Model.nameof(p => p.PageSize)' //每页数据量的参数名，默认：limit
        },
        where: {
            '@Model.nameof(m => m.SearchAccount)': ""
        },
        method: 'post',
        contentType: 'application/json;charset=UTF-8',
        limits: [@Model.AvailablePageSizes],
        limit: @Model.PageSize,
        cols: [[
            //{ type: "checkbox", width: 50, fixed: "left" },
            { field: 'Id', title: 'ID', width: 50, align: "center" },
            {
                field: '@adminuserModel.nameof(p => p.UserLoginName)', title: '@(ReflectionExtensions.GetPropertyDisplayName<AdminUserModel>(m => m.UserLoginName))',
                templet: function (d) {
                    if (d.IsAdmin) return d.UserLoginName + '<span class="layui-badge-dot toolgroup" data-tips="系统管理员"></span>';
                    else return d.UserLoginName;
                }
            },
            { field: '@adminuserModel.nameof(p => p.UserName)', title: '@(ReflectionExtensions.GetPropertyDisplayName<AdminUserModel>(m => m.UserName))'},
            { field: '@adminuserModel.nameof(p => p.RoleNames)', title: '@(ReflectionExtensions.GetPropertyDisplayName<AdminUserModel>(m => m.AvailableAdminRoles))'/*, templet: '#roleNameTpl'*/  },
            { field: '@adminuserModel.nameof(p => p.IsActive)', title: '@(ReflectionExtensions.GetPropertyDisplayName<AdminUserModel>(m => m.IsActive))', width: 150, templet: '#isActiveTpl' },
            { title: '操作', minWidth: 100, templet: '#tableitemBars',fixed: "right", align: "center" }
        ]],
        parseData: function (res) {
            return {
                "code": res.state == 200 ? 0 : -1,     //解析接口状态
                "msg": res.message,     //解析提示文本
                "count": res.state == 200 ? res.data.RecordsTotal : 0, //解析数据长度
                "data": res.state == 200 ? res.data.Data : []   //解析数据列表
            };
        },
        page: true
    };
    </script>
    <script src="~/js/backend/adminusermanage/adminusermanage.min.js" charset="utf-8" asp-append-version="true"></script>
}
